home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / edit.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  24KB  |  823 lines

  1. /*
  2.     GWAda Development Environment for 386/486 PCs   
  3.     Copyright (C) 1993, Arthur Vargas Lopes  & Michael Bliss Feldman
  4.                         vlopes@vortex.ufrgs.br mfeldman@seas.gwu.edu
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; version 2 of the License.    
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /* edit.c */
  21.  
  22. #include "externs.h"
  23.  
  24.  
  25. int AVL_COL()
  26. {
  27.     AVL_EDIT_WINDOW_PTR w;
  28.     int i, j = 0, n, n2 = 0;
  29.     char *t, line [30];
  30.     w = &avl_windows[avl_window];
  31.     t = w -> current_line -> line;
  32.     n = strlen(t);
  33.     for(i = 0; i <= w -> txt_col; ++i)  {
  34.         if (*(t + i) == '\t' && i != w -> txt_col)  {
  35.             for (n2= 0; !(((j + 1) % w -> tabsize) == 0); ++n2)    
  36.                 j++;
  37.             j++;
  38.             }
  39.         else 
  40.             j++;
  41.         }
  42.     return j;
  43. }
  44.  
  45.  
  46.  
  47. void AVL_JOIN_RIGHT() /* Join current line with next */
  48. {
  49.     AVL_EDIT_WINDOW_PTR w;
  50.     AVL_LINE_PTR temp, temp2;
  51.     struct rccoord old;
  52.     int pos, pos2;
  53.     w = &avl_windows[avl_window];
  54.     if (w -> current_line -> next != w -> head)  {
  55.         pos2 = w -> txt_col;
  56.         if ((strlen(w -> current_line -> line) + strlen(w -> current_line -> next -> line)) >= AVL_MAX_LINEL)  {
  57.             AVL_ERROR("Lines are too long. Can't perform join!");
  58.             return;
  59.             }
  60.         if (w -> scr_row < (w -> r2 - w -> r1 + 1))  {
  61.             old = _settextposition(w -> scr_row+1,w -> scr_col);
  62.             AVL_DELETE_LINE();
  63.             }
  64.         else
  65.             old = _settextposition(w -> scr_row,w -> scr_col);
  66.         
  67.         temp = w -> current_line -> next;
  68.         strcat(w -> current_line -> line,temp -> line);
  69.         w -> current_line -> next = temp -> next;
  70.         temp -> next -> previous = w -> current_line;
  71.         AVL_MAKE_NUMBER();
  72.         free(temp);
  73.         pos = w -> scr_row;
  74.         temp = temp2 = w -> current_line;
  75.         while (++pos != (w -> r2 - w -> r1 + 1) && temp -> next != w -> head)    {
  76.             temp = temp -> next;
  77.             }
  78.         if (pos == (w -> r2 - w -> r1 + 1) && temp != w -> head)  {
  79.             w -> current_line = temp;
  80.             w -> scr_row = w -> r2 - w -> r1 + 1;
  81.             _settextposition( w -> scr_row, 1);
  82.             AVL_UPDATE_LINE();
  83.             }
  84.         w -> current_line = temp2;
  85.         old = _settextposition(w -> scr_row = old.row,w -> scr_col = old.col);
  86.         w -> txt_col = pos2;
  87.         w -> changed = 1;
  88.         AVL_UPDATE_LINE();
  89.         }
  90. }        
  91.  
  92. void AVL_JOIN_LEFT() /* Join current line with Previos */
  93. {
  94.     AVL_EDIT_WINDOW_PTR w;
  95.     AVL_LINE_PTR temp, temp2;
  96.     struct rccoord old;
  97.     int pos, pos2;
  98.     w = &avl_windows[avl_window];
  99.     if (w -> current_line -> previous != w -> head)  {
  100.         if ((strlen(w -> current_line -> line) + strlen(w -> current_line -> previous -> line)) >= AVL_MAX_LINEL)  {
  101.             AVL_ERROR("Lines are too long. Can't perform join!");
  102.             return;
  103.             }
  104.         old = _settextposition(w -> scr_row+1,w -> scr_col);
  105.         temp = w -> current_line;
  106.         w -> current_line = w -> current_line -> previous;
  107.         AVL_CURSOR_END();
  108.         pos2 = w -> txt_col;
  109.         strcat(w -> current_line -> line, temp -> line);
  110.         w -> current_line -> next = temp -> next;
  111.         temp -> next -> previous = w -> current_line;
  112.         AVL_MAKE_NUMBER();
  113.         free(temp);
  114.         if (w -> scr_row != 1)
  115.             AVL_DELETE_LINE();
  116.         pos = w -> scr_row;
  117.         temp = temp2 = w -> current_line;
  118.         while (++pos != (w -> r2 + 1) && temp -> next != w -> head)    {
  119.             temp = temp -> next;
  120.             }
  121.         if (pos == (w -> r2 + 1) && temp != w -> head)  {
  122.             w -> current_line = temp;
  123.             w -> scr_row = (w -> r2 - 1);
  124.             _settextposition( (w -> r2 - 1), 1);
  125.             AVL_UPDATE_LINE();
  126.             }
  127.         w -> current_line = temp2;
  128.         if (old.row > 1)
  129.             old = _settextposition(w -> scr_row = old.row - 1,w -> scr_col = old.col);
  130.         else
  131.             old = _settextposition(w -> scr_row = old.row,w -> scr_col = old.col);
  132.         w -> txt_col = pos2;
  133.         AVL_UPDATE_LINE();
  134.         w -> changed = 1;
  135.         }
  136. }        
  137.  
  138.  
  139. int AVL_OFFSET()
  140. {
  141.     AVL_EDIT_WINDOW_PTR w;
  142.     int n, i, off = 0;
  143.     w = &avl_windows[avl_window];
  144.     n = AVL_COL();
  145.     off = 0;
  146.     for(i = (w -> c2 - w -> c1 + 1); i < n; i += 20)
  147.         off += 20;
  148.     return ( off );
  149. }
  150.  
  151. int AVL_COUNT()
  152. {
  153.     int i = 0;
  154.     AVL_EDIT_WINDOW_PTR w;
  155.     w = &avl_windows[avl_window];
  156.     avl_line_temp = w -> current_line;
  157.     for (; avl_line_temp != w -> head 
  158.            && i < w -> r2; avl_line_temp = avl_line_temp -> next)
  159.         ++i;
  160.     avl_line_temp = avl_line_temp -> previous;
  161.     return i;
  162. }
  163.  
  164. void AVL_OPEN_LINE()
  165. {
  166.    short left, top, right, bottom;
  167.    struct rccoord rc;
  168.  
  169.    _gettextwindow( &top, &left, &bottom, &right );
  170.    rc = _gettextposition();
  171.    _settextwindow( rc.row+1, left, bottom, right );
  172.    _scrolltextwindow( _GSCROLLDOWN );
  173.    _settextwindow( top, left, bottom, right );
  174.    _settextposition( rc.row+1, rc.col );
  175. }
  176.  
  177. void AVL_EDIT_ENTER()
  178. {
  179.     AVL_EDIT_WINDOW_PTR w;
  180.     AVL_LINE_PTR temp;
  181.     struct rccoord old;
  182.     short i, j, k;
  183.     old = _gettextposition();
  184.     w = &avl_windows[avl_window];
  185.     for(i = 0, j = 0; w -> current_line -> line [i] == ' '; ++i);
  186.     j = i;
  187.     temp = calloc(1,sizeof(AVL_LINE_SIZE));
  188.     temp -> previous = w -> current_line;
  189.     temp -> next     = w -> current_line -> next;
  190.     w -> current_line -> next -> previous = temp;
  191.     w -> current_line -> next = temp;
  192.     strcpy(temp -> line, w -> current_line -> line + w -> txt_col);
  193.     w -> current_line -> line [w -> txt_col] = '\0';
  194.     AVL_MAKE_NUMBER();
  195.     w -> txt_col = 0;
  196.     AVL_OPEN_LINE();
  197.     _settextposition(w -> scr_row,w -> scr_col = 1);
  198.     AVL_UPDATE_LINE();
  199.     if (w -> scr_row == (w -> r2 - w -> r1 + 1)) 
  200.         _scrolltextwindow( 1 );
  201.     else
  202.         w -> scr_row += 1;
  203.     w -> current_line = temp; 
  204.     w -> changed = 1;
  205.     if (strlen(temp -> line) > 0)
  206.         j = 0;  
  207.     for(i = 0; i < j; ++i)
  208.         w -> current_line -> line[i] = ' ';
  209.     if (j > 0)
  210.         w -> current_line -> line[i] = '\0';
  211.     _settextposition(w -> scr_row,w -> scr_col = (j < 78) ? j + 1 : 1);
  212.     w -> txt_col = (j < 78) ? j : 0;
  213.     AVL_UPDATE_LINE();
  214.     if (w -> offset != 0)  {
  215.         w -> offset = 0;
  216.         AVL_SCROLL();
  217.         }
  218. }
  219.  
  220. void AVL_SCROLL()
  221. {
  222.     AVL_EDIT_WINDOW_PTR w;
  223.     AVL_LINE_PTR temp;
  224.     struct rccoord old;
  225.     short i, j, k;
  226.     AVL_WIN_PTR t, t2;
  227.     w = &avl_windows[avl_window];
  228.     old = _gettextposition();
  229.     temp = w -> current_line;
  230.     j = old.row;
  231. /*
  232.     if ((w -> txt_col == strlen(temp -> line)) && (w -> txt_col > 0))
  233.         w -> txt_col -= 1;
  234. */
  235.     k = w -> txt_col;
  236.     for(i = j; i > 1; --i)  {
  237.         w -> current_line = w -> current_line -> previous;
  238.         }
  239.     w -> scr_row = 1;
  240.     avl_hscroll_on = 1;
  241.     _settextposition(1,1);
  242.     AVL_UPDATE_SCREEN();
  243.     _settextposition(old.row,old.col);
  244.     w -> current_line = temp;
  245.     w -> scr_row = j;
  246.     w -> scr_col = old.col;
  247.     w -> txt_col = k;
  248.     avl_hscroll_on = 0;
  249.     AVL_UPDATE_CURSOR();
  250. }
  251.  
  252.  
  253.  
  254. void AVL_UPDATE_STATUS_LINE()
  255. {
  256.     AVL_EDIT_WINDOW_PTR w;
  257.     char status[10];
  258.     char line[181];
  259.     char fn[121];
  260.     short att, attold;
  261.     short i, n;
  262.     char *p;
  263.     w = &avl_windows[avl_window];
  264.     attold = _gettextcursor();
  265.     if (w -> no_status == 'N') return;
  266.     if (avl_window < AVL_MAX_WINDOWS)
  267.         switch (tolower(w -> edit_mode))  {
  268.             case 'x' : strcpy(status,"Ovr"); att = 0x0007; break;
  269.             case 'i' : strcpy(status,"Ins"); att = 0x0707; break;
  270.             default  : w -> edit_mode = 'i'; strcpy(status,"Ins"); att = 0x0707; break;
  271.             }
  272.     else
  273.         strcpy(status,"Hlp");
  274.     AVL_MAKE_FN(fn, w -> file_name);
  275.     sprintf(line,"Line %3d Col %2d %-35s %s %-12s F1-Help             "
  276.         ,  w -> current_line -> line_no - 1
  277.         , w -> txt_col + 1
  278.         , avl_message
  279.         , status
  280.         , fn
  281.         );
  282.     n = strlen(line);
  283.     if (n > 80) n = 80;
  284.     p = line;
  285.     for(i = 1; i <= n; ++i, ++p)
  286. /*        AVL_PUT(*p,w -> r1 - 1,i,avl_sta_bk_color,avl_sta_color);   */
  287.         AVL_WVIDEO(*p,(unsigned char) (avl_sta_bk_color << 4 | avl_sta_color)
  288.             , AVL_MAP(w -> r1 - 1,i));
  289.     if (attold != att)
  290.         _settextcursor(att);    
  291. }
  292.  
  293.  
  294. void AVL_INIT_WINDOW(AVL_EDIT_WINDOW_PTR w, AVL_LINE_PTR first)
  295. {
  296.     short att;
  297.     att = _settextcursor(0x0607);
  298.     avl_find_txt[0] = '\0';
  299.     avl_replace_txt[0] = '\0';
  300.     avl_block_first_line = NULL;
  301.     avl_block_last_line = NULL;
  302.     avl_block_first_col = 0;
  303.     avl_block_last_col = 0;
  304.     sprintf(avl_blank_line,"%80s"," ");
  305.     w -> head         = first -> previous;
  306.     w -> current_line = first;
  307.     w -> no_status = 'Y';
  308.     w -> r1     = 2;
  309.     w -> c1     = 1;
  310.     w -> r2     = 25;
  311.     w -> c2     = 80;
  312.     w -> offset = 0;
  313.     w -> edit_mode = 'i';
  314.     w -> tabsize   = avl_tab_size;
  315.     w -> scr_col   = 1;
  316.     w -> scr_row   = 1;
  317.     w -> txt_col   = 0;
  318.     w -> line_no = 0;
  319.     avl_message[0] = '\0';
  320.     _settextwindow(w -> r1, w -> c1, w -> r2, w -> c2);
  321.     _setbkcolor( avl_txt_bk_color );
  322.     _settextcolor( avl_txt_color );
  323. }
  324.  
  325. char *AVL_MAKE_TXT_LINE()
  326. {
  327.     char *d;
  328.     int i, j = 0, n, n2 = 0;
  329.     AVL_EDIT_WINDOW_PTR w;
  330.     char *t, *t2;
  331.     w = &avl_windows[avl_window];
  332.     t = w -> current_line -> line;
  333.     d = w -> expanded_line;
  334.     n = strlen(t);
  335.     for(i = 0; i < n; ++i)  {
  336.         if (*(t + i) == '\t')  {
  337.             for (n2= 0; !(((j + 1) % w -> tabsize) == 0); ++n2)
  338.                 d[j++] = ' ';
  339.             d[j++] = ' ';
  340.             }
  341.         else 
  342.             d[j++] = *(t + i);
  343.         }
  344.     d[j] = '\0';        
  345.     return d;
  346. }        
  347.  
  348. void AVL_UPDATE_LINE()
  349. {
  350.     short i, j, k;
  351.     char *d;
  352.     char *p;
  353.     AVL_EDIT_WINDOW_PTR w;
  354.     w = &avl_windows[avl_window];
  355.     d = AVL_MAKE_TXT_LINE();
  356.     j = strlen(d);
  357.     if (w -> txt_col > (k = strlen(d)))
  358.         w -> txt_col = k;
  359.     if (w -> txt_col < 0) 
  360.         w -> txt_col = 0;
  361.     if (j <= w -> offset)
  362.         j = 0;
  363.     else
  364.         j = j - w -> offset + 1;
  365.     k = w -> scr_row + w -> r1 - 1;
  366.     i = (j > (w -> c2 - w -> c1 + 1)) ? (w -> c2 - w -> c1 + 1) : j;
  367.     p = d + w -> offset;
  368.     for(j = 1; j <= i; ++j, ++p)
  369.         AVL_WVIDEO(*p,(unsigned char) (avl_txt_bk_color << 4 | avl_txt_color) 
  370.             , AVL_MAP(k,j));
  371. /*        AVL_PUT(*p,k,j,avl_txt_bk_color,avl_txt_color);   */
  372.     for(; j <= (w -> c2 - w -> c1 + 1); ++j)
  373.         AVL_WVIDEO(' ',(unsigned char) (avl_txt_bk_color << 4 | avl_txt_color), AVL_MAP(k,j));
  374. /*        AVL_PUT(' ',k,j,avl_txt_bk_color,avl_txt_color);  */
  375.     strcpy(w -> current_line -> line,d);
  376.     if (!avl_hscroll_on)
  377.         AVL_UPDATE_CURSOR();
  378. }
  379.  
  380.  
  381. void show_sit(char *s)
  382. {
  383.     struct rccoord old;
  384.     static short x = 0;
  385.     AVL_EDIT_WINDOW_PTR w;
  386.     int n, j;
  387.     char msg[200];
  388.     if (x >= 6) x = 0;
  389.     w = &avl_windows[avl_window];
  390.     n = strlen(w -> current_line -> line);
  391.     old = _gettextposition();
  392.     _settextposition(10+x++,1);
  393.     sprintf(msg,"%s offset=%d scr_col=%d txt_col=%d len=%d char=%c[%d]", s, 
  394.         w -> offset, w -> scr_col, w -> txt_col, n 
  395.         , w -> current_line -> line [w -> txt_col]
  396.         , w -> current_line -> line [w -> txt_col]);
  397.     _outtext(msg);
  398.     j = getch();
  399.     _settextposition(old.row,old.col);
  400. }
  401.  
  402. void AVL_EDIT_INSERT(int ch)
  403. {
  404.     AVL_EDIT_WINDOW_PTR w;
  405.     short n, j, oldoffset;
  406.     char *p;
  407.     w = &avl_windows[avl_window];
  408.     oldoffset = w -> offset;
  409.     n = strlen(w -> current_line -> line);
  410. /*    if (w -> txt_col >= n)  
  411.         AVL_CURSOR_END();
  412. */
  413.     if (n >= AVL_MAX_LINEL) { putchar(7); return; }
  414.     if (w -> edit_mode == 'i') {   /*  Insert mode */
  415.         if ((n + 1) >= AVL_MAX_LINEL) { putchar(7); return; }
  416.         for (j = n; j >= w -> txt_col; --j)
  417.             w -> current_line -> line[j + 1] = w -> current_line -> line[j];
  418.         w -> current_line -> line[w -> txt_col] = ch;
  419.         }
  420.     else {
  421.         w -> current_line -> line[w -> txt_col] = ch;
  422.         if (w -> txt_col >= n)  {
  423.             w -> current_line -> line[w -> txt_col+1] = '\0';
  424.             }
  425.         }
  426.     w -> txt_col += 1;
  427.     w -> offset = AVL_OFFSET();
  428.     if (w -> offset != oldoffset)  
  429.         AVL_SCROLL();
  430.     w -> buffer_size += 1;
  431.     w -> changed = 1;
  432.     n = strlen(w -> current_line -> line);
  433.     AVL_UPDATE_LINE();
  434.     j = strlen(w -> current_line -> line);
  435.     if (j != n)  {
  436.         w -> txt_col += (j - n);
  437.         AVL_UPDATE_CURSOR();
  438.         }
  439. /*show_sit("Depois ==> ");
  440. */
  441. }
  442.  
  443.     AVL_FLIP_MODE()
  444. {
  445.     AVL_EDIT_WINDOW_PTR w;
  446.     w = &avl_windows[avl_window];
  447.     switch (tolower(w -> edit_mode))  {
  448.         case 'c' : w -> edit_mode = 'i';  break;
  449.         case 'i' : w -> edit_mode = 'x';  break;
  450.         case 'x' : w -> edit_mode = 'i';  break;
  451.         default  : AVL_ERROR("Invalid status mode..."); exit(1);
  452.         }
  453.     AVL_UPDATE_STATUS_LINE();
  454. }
  455.  
  456. void AVL_HOT_KEYS()
  457. {
  458.     AVL_WIN_PTR win;
  459.     win = AVL_MAKE_WINDOW(" Hot Keys ",4,3,17,76,avl_wnd_bk_color,avl_wnd_color);
  460.     /*          1         2         3         4         5         6         7 */
  461.     /* 1234567890123456789012345678901234567890123456789012345678901234567890 */
  462.     /* 
  463.  
  464.          Alternate keys: File Edit Compile Bind Run Window Options Ada Help
  465.                          F4 quit
  466.  
  467.                          Example: Alt-F ==> activates the File Menu
  468.  
  469.          Editing keys:   F5      goto line        Ctrl-G  delete char
  470.                          Ctrl-KB begin block      Ctrl-Y  delete line      
  471.                          Ctrl-KK end block        Ctrl-QR go begin text
  472.                          Ctrl-KC copy block       Ctrl-RC go end text
  473.                          Ctrl-KS save             Ins     insert/over. mode
  474.             
  475.     */
  476.     _settextcolor(avl_men_letter);
  477.     _settextposition(2,3);  _outtext("Alternate keys: ");
  478.     _settextcolor(avl_men_ready); _outtext("F");
  479.     _settextcolor(avl_men_letter); _outtext("ile ");
  480.     _settextcolor(avl_men_ready); _outtext("E");
  481.     _settextcolor(avl_men_letter); _outtext("dit ");
  482.     _settextcolor(avl_men_ready); _outtext("C");
  483.     _settextcolor(avl_men_letter); _outtext("ompile ");
  484.     _settextcolor(avl_men_ready); _outtext("B");
  485.     _settextcolor(avl_men_letter); _outtext("ind ");
  486.     _settextcolor(avl_men_ready); _outtext("R");
  487.     _settextcolor(avl_men_letter); _outtext("un ");
  488.     _settextcolor(avl_men_ready); _outtext("W");
  489.     _settextcolor(avl_men_letter); _outtext("indow ");
  490.     _settextcolor(avl_men_ready); _outtext("O");
  491.     _settextcolor(avl_men_letter); _outtext("ptions ");
  492.     _settextcolor(avl_men_ready); _outtext("A");
  493.     _settextcolor(avl_men_letter); _outtext("da ");
  494.     _settextcolor(avl_men_ready); _outtext("H");
  495.     _settextcolor(avl_men_letter); _outtext("elp");
  496.     _settextposition(3,19); _settextcolor(avl_men_ready); _outtext("F4");
  497.      _settextcolor(avl_men_letter); _outtext(" quit");
  498.     _settextposition(5,19); _outtext("Example: ");
  499.     _settextcolor(avl_men_ready); _outtext("Alt-F");
  500.     _settextcolor(avl_men_letter); _outtext(" ==> activates the File Menu");
  501.     _settextposition(7,3);  _outtext("Editing keys:   ");
  502.     _settextcolor(avl_men_ready); _outtext("F5");
  503.     _settextcolor(avl_men_letter); _outtext("      goto line        ");
  504.     _settextcolor(avl_men_ready); _outtext("Ctrl-G");
  505.     _settextcolor(avl_men_letter); _outtext("  delete char");
  506.     _settextposition(8,19); _settextcolor(avl_men_ready); _outtext("Ctrl-KB");
  507.     _settextcolor(avl_men_letter); _outtext(" begin block      ");
  508.     _settextcolor(avl_men_ready); _outtext("Ctrl-Y");
  509.     _settextcolor(avl_men_letter); _outtext("  delete line");
  510.     _settextposition(9,19); _settextcolor(avl_men_ready); _outtext("Ctrl-KK");
  511.     _settextcolor(avl_men_letter); _outtext(" end block        ");
  512.     _settextcolor(avl_men_ready); _outtext("Ctrl-QR");
  513.     _settextcolor(avl_men_letter); _outtext(" go begin text");
  514.     _settextposition(10,19); _settextcolor(avl_men_ready); _outtext("Ctrl-KC");
  515.     _settextcolor(avl_men_letter); _outtext(" copy block       ");
  516.     _settextcolor(avl_men_ready); _outtext("Ctrl-RC");
  517.     _settextcolor(avl_men_letter); _outtext(" go end text");
  518.     _settextposition(11,19);_settextcolor(avl_men_ready);  _outtext("Ctrl-KS");
  519.     _settextcolor(avl_men_letter); _outtext(" save             ");
  520.     _settextcolor(avl_men_ready); _outtext("Ins");
  521.     _settextcolor(avl_men_letter); _outtext("     insert/over. mode");
  522.     AVL_PAUSE(20);
  523.     AVL_DEL_WINDOW(win);
  524. }
  525.  
  526.  
  527. void AVL_WORD_BACKWARD()
  528. {
  529.     AVL_EDIT_WINDOW_PTR w;
  530.     char *p, *q;
  531.     w = &avl_windows[avl_window];
  532.     p = &( w -> current_line -> line[w -> txt_col] );
  533.     q = &( w -> current_line -> line[0] );
  534.     while (!(p == q || *p == ' ')) {  /* skip letters going left */
  535.         AVL_CURSOR_LEFT(1);           /* getting out of current word */
  536.         --p;
  537.         }
  538.     if (*p == ' ' && p != q) /* is there a blank? */
  539.         do { /* skip blanks */
  540.             AVL_CURSOR_LEFT(1); 
  541.             --p;
  542.             } while (*p == ' ' && p != q);
  543.     if (p != q)  { /* are we at the right of a symbol? */
  544.         while (!(p == q || *p == ' ')) {
  545.             AVL_CURSOR_LEFT(1); 
  546.             --p;
  547.             }
  548. /*        if (p != q)  {
  549.             AVL_CURSOR_RIGHT(1);   
  550.             ++p;
  551.             }
  552. */
  553.           }
  554.     if (*p == ' ')  
  555.         do {
  556.             AVL_CURSOR_RIGHT(1);   
  557.             ++p;
  558.             } while (*p == ' ');
  559. }
  560.  
  561. void AVL_WORD_FORWARD()
  562. {
  563.     AVL_EDIT_WINDOW_PTR w;
  564.     char *p;
  565.     w = &avl_windows[avl_window];
  566.     p = &( w -> current_line -> line[w -> txt_col] );
  567.     while (!(*p == '\0' || *p == ' ')) {
  568.         AVL_CURSOR_RIGHT(1); 
  569.         ++p;
  570.         }
  571.     if (*p == ' ') 
  572.         do {
  573.             AVL_CURSOR_RIGHT(1); 
  574.             ++p;
  575.             } while (*p == ' ');
  576. }    
  577.         
  578. void AVL_DO_HELP_INDEX(char *s, short pos)
  579. {
  580.     short i, k;
  581.     short nopt = 0;
  582.     char word[200];
  583.     char do_call[300];
  584.     char c;
  585.     char *opts[17];
  586.     c = *(s+pos);
  587.     if (!(isalpha(c) || c == '_')) {
  588.         AVL_ERROR("Activate the Search Help (F8) when the cursor is over a word");
  589.         return;
  590.         }
  591.     i = pos;
  592.     while (i >=0 && (isalpha(*(s+i)) || *(s+i) == '_')) --i;
  593.     if (i < 0) i = 0;
  594.     else ++i;
  595.     k = 0;
  596.     while (isalpha(*(s+i)) || *(s+i) == '_') word[k++] = *(s+i++);
  597.     word[k] = '\0';
  598.     opts[nopt++] = "Adahelp";
  599.     opts[nopt++] = word;
  600.     opts[nopt++] = NULL;
  601.     sprintf(do_call,"ADAHELP %s",word);
  602.     system(do_call);
  603. /*
  604.     if (AVL_EX_UNIT("ADAHELP", opts))  ;
  605. */
  606. }
  607.  
  608. void AVL_EDIT(char mode)
  609. {
  610.     int ch, no = 1;
  611.     char c;
  612.     int updt = 1;
  613.     short r1, r2, c1, c2, i, j;
  614.     extern int avl_ctrl_c;
  615.     AVL_LINE_PTR saved;
  616.     AVL_EDIT_WINDOW_PTR w;
  617.     short old_bk_color, old_color;
  618.     short old_sta_bk_color, old_sta_color;
  619.     w = &avl_windows[avl_window];
  620.     w -> edit_mode = mode;
  621.     strcpy(avl_message,"Press ESC to activate top menu");
  622.     AVL_UPDATE_CURSOR();
  623.     AVL_UPDATE_STATUS_LINE();
  624.     old_color = avl_txt_color;
  625.     old_bk_color = avl_txt_bk_color;
  626.     old_sta_color = avl_sta_color;
  627.     old_sta_bk_color = avl_sta_bk_color;
  628.     while ( 1 )  {
  629.         w = &avl_windows[avl_window];
  630.         if (!((old_sta_bk_color == avl_sta_bk_color) && (old_sta_color == avl_sta_color))) {
  631.             for(j = 1; j <= 80; ++j)  {
  632.                 c = *AVL_MAP(1,j);
  633.                 AVL_WVIDEO(c,(unsigned char) (avl_sta_bk_color << 4 | avl_sta_color), AVL_MAP(1,j));
  634.                 }
  635.             old_sta_bk_color = avl_sta_bk_color;
  636.             old_sta_color = avl_sta_color;
  637.             }
  638.         if (!((old_bk_color == avl_txt_bk_color) && (old_color == avl_txt_color))) {
  639.             _gettextwindow(&r1,&c1,&r2,&c2);
  640.             for(i = r1; i <= r2; ++i)
  641.                 for(j = c1; j <= c2; ++j)  {
  642.                     c = *AVL_MAP(i,j);
  643.                     AVL_WVIDEO(c,(unsigned char) (avl_txt_bk_color << 4 | avl_txt_color), AVL_MAP(i,j));
  644.                     }
  645.             old_bk_color = avl_txt_bk_color;
  646.             old_color = avl_txt_color;
  647.             }
  648.  
  649.         if (avl_open_error_file)  {
  650.             AVL_ENVIRONMENT('F');
  651.             avl_open_error_file = 0;
  652.             continue;
  653.             }
  654.  
  655.         if (!kbhit()) {
  656.             if (updt)  {
  657.                 AVL_UPDATE_CURSOR();
  658.                 AVL_UPDATE_STATUS_LINE();
  659.                 updt = 0;
  660.                 }
  661.             continue;
  662.             }
  663.         updt = 1;
  664.         ch = getch();
  665.         switch( ch )  {
  666.             case  1  : /* Ctrl-Left == Ctrl-A */ AVL_WORD_BACKWARD(); break;
  667.             case  6  : /* Ctrl-Right == Ctrl-F */ AVL_WORD_FORWARD(); break;
  668.             case  4  : /* Ctrl-D == Right */  AVL_CURSOR_RIGHT(1); break;
  669.             case  8  : { /*  Backspace */  
  670.                 if (w -> txt_col > 0) {
  671.                     w -> txt_col -= 1;
  672.                     if (w -> offset != AVL_OFFSET()) {
  673.                         w -> offset = AVL_OFFSET();
  674.                         AVL_SCROLL();
  675.                         }
  676.                     AVL_EDIT_DEL_RIGHT(no); 
  677.                     no = 0; 
  678.                     }
  679.                 else {  /* Join with the previous line */
  680.                     w -> changed = 1;
  681.                     w -> offset = 0;
  682.                     AVL_JOIN_LEFT();
  683.                     }
  684.                 break;
  685.                 }
  686.             case  9  :  /*  Tab       */  AVL_EDIT_INSERT(ch); break;
  687.             case 14  :  /*  Ctrl-N */
  688.             case 13  :  /*  Enter     */  AVL_EDIT_ENTER(); break;
  689.             /*  Control keys */
  690.             case  7 : /* Delete current char - Ctrl G */
  691.                 AVL_EDIT_DEL_RIGHT(no); 
  692.                 no = 0; 
  693.                 break;
  694.             case 11 : /* Mark Block - Ctrl K */
  695.                 ch = toupper(getch());
  696.                 if (ch == 'B' || ch == 'K') {
  697.                     AVL_GUIDE_MBLOCK ();
  698.                     break;
  699.                     }
  700.                 else if (ch == 'C')  {
  701.                     AVL_PROCESS_COPY();
  702.                     break;
  703.                     }
  704.                 else if (ch == 'S')  {
  705.                     AVL_SAVE();
  706.                     break;
  707.                     }
  708.                 if (ch == 0) ch = getch();
  709.                 AVL_ERROR("Use only Ctrl-k b, Ctrl-k k, Ctrl-k c and Crtl-k s");
  710.                 break;
  711.             case 17 : /* Go to begin/end of text file  Ctrl-Q R or C or Y */
  712.                 avl_ctrl_c = 0;
  713.                 ch = toupper(getch());
  714.                 if (ch == 89 || ch == 25)   {  /* Got a Ctrl-Q Y */
  715.                     w -> current_line -> line [w -> txt_col] = '\0';
  716.                     AVL_UPDATE_LINE();
  717.                     break;
  718.                     }
  719.                 AVL_UPDATE_LINE();
  720.                 if (ch == 'C' || avl_ctrl_c) {
  721.                     if (w -> head -> previous != w -> head)
  722.                         AVL_DO_GOTO(w -> head -> previous -> line_no);
  723.                     break;
  724.                     }
  725.                 else if (ch == 'R' || ch == 18) {
  726.                     avl_ctrl_c = 0;
  727.                     if (w -> head -> next != w -> head)
  728.                         AVL_DO_GOTO(w -> head -> next -> line_no);
  729.                     break;
  730.                     }
  731.                 if (ch == 0) ch = getch();
  732.                 AVL_ERROR("Use only Ctrl-q r, Ctrl-q c or Ctrl-q y");
  733.                 break;
  734.             case 22 : /* Ctrl-V == Ins key */ AVL_FLIP_MODE(); break;
  735.             case 25 : /* Delete current line - Ctrl Y */
  736.                 AVL_EDIT_DEL_LINE(no); 
  737.                 no = 0; 
  738.                 break;
  739.             case 27  :  /*  ESC       */  
  740.                 if (avl_cur_menu == 7 && avl_window == AVL_MAX_WINDOWS) 
  741.                     return;
  742.                 else {
  743.                     if (do_not_realy_exit) {
  744.                         AVL_EXIT();
  745.                         return;
  746.                         }
  747.                     AVL_ENVIRONMENT(0); 
  748.                     AVL_UPDATE_CURSOR();
  749.                     AVL_UPDATE_STATUS_LINE();
  750.                     updt = 1;
  751.                     break;
  752.                     }
  753.  
  754.                 break;
  755.             case  0  : {
  756.                 ch = getch();
  757.                 switch( ch ) {
  758.                     /*  Alt keys  */
  759.                     case 33 : /* File */ AVL_ENVIRONMENT('F'); break;
  760.                     case 59 : /* F1 without alternate   */ AVL_HOT_KEYS(); break;
  761.                     case 60 : /* F2 without alternate */ AVL_ENVIRONMENT('F'); break;
  762.                     case 66 : /* F8 without alternate */ AVL_DO_HELP_INDEX(w -> current_line -> line,w -> txt_col); break;
  763.                     case 18 : /* Edit */ AVL_ENVIRONMENT('E'); break;
  764.                     case 46 : /* Comp */ AVL_ENVIRONMENT('C'); updt = 1; break;
  765.                     case 48 : /* Bind */ AVL_ENVIRONMENT('B'); break;
  766.                     case 19 : /* Run  */ AVL_ENVIRONMENT('R'); break;
  767.                     case 17 : /* Wind */ AVL_ENVIRONMENT('W'); updt = 1; break;
  768.                     case 24 : /* Opti */ AVL_ENVIRONMENT('O'); break;
  769.                     case 30 : /* Ada  */ AVL_ENVIRONMENT('A'); break;
  770.                     case 35 : /* Help */ AVL_ENVIRONMENT('H'); break;
  771.                     case 107: /* Alt-F4   */ AVL_EXIT(); return;
  772.                     case 63 : /* F5   */ AVL_GOTO(); break;    
  773.                     case 65 : /* F7 */ AVL_BODY(); break;
  774.                     case 68 : /* F10 */
  775.                         if (avl_cur_menu == 7 && avl_window == AVL_MAX_WINDOWS) 
  776.                             return;
  777.                         else {
  778.                             if (do_not_realy_exit) {
  779.                                 AVL_EXIT();
  780.                                 return;
  781.                                 }
  782.                             AVL_ENVIRONMENT(0); 
  783.                             AVL_UPDATE_CURSOR();
  784.                             AVL_UPDATE_STATUS_LINE();
  785.                             updt = 1;
  786.                             break;
  787.                             }
  788.  
  789.                     case 82 : /* Ins  */ AVL_FLIP_MODE(); break;
  790.                     case 83 : /* Del  */ AVL_EDIT_DEL_RIGHT(no); no = 0; break;
  791.                     case 71 : /* Home */ AVL_CURSOR_HOME(); break;
  792.                     case 79 : /* End  */ AVL_CURSOR_END(); break;
  793.                     case 73 : /* PgUp */ AVL_CURSOR_PGUP(); break;
  794.                     case 81 : /* PgDn */ AVL_CURSOR_PGDN(); break;
  795.                     case 75 : /* Left */ AVL_CURSOR_LEFT(no); no = 0; break;
  796.                     case 77 : /* Right*/ AVL_CURSOR_RIGHT(no); no = 0; break;
  797.                     case 72 : /* Up   */ AVL_CURSOR_UP  (no); no = 0; break;
  798.                     case 80 : /* Down */ AVL_CURSOR_DOWN(no); no = 0; break;
  799.                     case 85 : /* SHIFT+F2 == Ctrl-K S */ AVL_SAVE(); break;
  800.                     case 92 : /* Shift+F9 == Alt-F D */ AVL_DOS_CMD(); break;
  801.                     case 115 : /* Ctrl-Left == Ctrl-A */ AVL_WORD_BACKWARD(); break;
  802.                     case 116 : /* Ctrl-Right == Ctrl-F */ AVL_WORD_FORWARD(); break;
  803.                     case 117 : /* Ctrl-End */
  804.                         AVL_DO_GOTO(w -> head -> previous -> line_no);
  805.                         break;
  806.                     case 119 : /* Ctrl-Home */
  807.                         AVL_DO_GOTO(w -> head -> next -> line_no);
  808.                         break;
  809.                     default : putchar(7); break;
  810.                     }
  811.                 break;
  812.                 }
  813.             default : {
  814.                 if (ch >= 32 && ch <= 126)  /* ' ' && '~' */ 
  815.                     AVL_EDIT_INSERT(ch);
  816.                 else
  817.                     putchar(7);
  818.                 break;
  819.                 }               
  820.             }
  821.         }
  822. }
  823.